# -*- coding: utf-8 -*-
"""
@File: database.py.py
@author: chenxialin
@time: 9月 26, 2025 20:40
"""
# database.py
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

# 数据库连接字符串（请修改为你的实际密码）
DATABASE_URL = "mysql+pymysql://root:Zhangjie1128!@localhost:3306/qmt"

engine = create_engine(DATABASE_URL, pool_pre_ping=True)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

Base = declarative_base()

# 依赖项：获取 DB 会话
def get_db():
    db = SessionLocal()
    try:
        yield db
    finally:
        db.close()